import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/components/back_btn_icon.dart';
import 'package:share_fit/app/controllers/device/settings_more/logic.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/generated/locales.g.dart';

import 'logic.dart';

class BrightenScreenPage extends StatelessWidget {
  BrightenScreenPage({Key? key}) : super(key: key);

  final logic = Get.find<BrightenScreenLogic>();
  final state = Get.find<BrightenScreenLogic>().state;

  final settingsMoreLogic = Get.find<SettingsMoreLogic>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: BackBtnIcon(onTap: () => Get.back()),
        centerTitle: true,
        title: Text(LocaleKeys.settings_brighten_screen.ts, style: TextStyle(fontSize: 54.sp)),
      ),
      body: Padding(
        padding: EdgeInsets.only(top: 150.h, left: 41.w, right: 41.w),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Image.asset('assets/images/device/brighten_screen.png', width: 294.w, height: 242.w),
            Container(
              alignment: Alignment.center,
              margin: EdgeInsets.only(top: 128.h),
              padding: EdgeInsets.only(left: 57.w),
              constraints: BoxConstraints.expand(height: 247.h),
              decoration: BoxDecoration(color: Colors.white70.withOpacity(0.8), borderRadius: BorderRadius.circular(60.r)),
              child: ListTile(
                title: Obx(() => Text(settingsMoreLogic.getSelectItemText(), style: TextStyle(fontSize: 54.sp))),
                subtitle: Text(LocaleKeys.settings_br_set_time.ts, style: TextStyle(fontSize: 42.sp)),
                trailing: const Icon(Icons.arrow_forward_ios),
                onTap: () => _showBrightenScreenSettings(context),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Future<Future<int?>> _showBrightenScreenSettings(context) async {
    var controller = FixedExtentScrollController(initialItem: settingsMoreLogic.state.selectedValue.value);

    return showModalBottomSheet<int>(
      backgroundColor: Colors.black,
      isScrollControlled: true,
      context: context,
      builder: (BuildContext context) {
        return Container(
          clipBehavior: Clip.antiAlias,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.only(topLeft: Radius.circular(40.r), topRight: Radius.circular(40.r)),
          ),
          height: MediaQuery.of(context).size.height / 3.0,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              SizedBox(
                height: 150.h,
                child: Stack(
                  textDirection: TextDirection.rtl,
                  children: [
                    Center(child: Text(LocaleKeys.settings_br_set_time.ts, style: TextStyle(fontSize: 54.sp))),
                  ],
                ),
              ),
              Expanded(
                child: CupertinoPicker(
                  scrollController: controller,
                  // diameterRatio: 1,
                  // useMagnifier: true,
                  // magnification: 2,
                  // squeeze: 0.6,
                  // itemExtent: 25,

                  diameterRatio: 1,
                  useMagnifier: true, //使用放大镜
                  magnification: 1.3, //当前选中item放大倍数
                  itemExtent: 100.h, //行高
                  squeeze: 0.6,
                  onSelectedItemChanged: (index) {
                    settingsMoreLogic.setScreenOnDuration(index);
                  },
                  children: settingsMoreLogic.state.brightenScreenSelectChildren.map((data) {
                    return Center(
                      child: Text(data),
                    );
                  }).toList(),
                ),
              ),
              SizedBox(
                height: 150.h,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    GestureDetector(
                      child: Text(LocaleKeys.cancel.ts, style: TextStyle(fontSize: 42.sp)),
                      onTap: () => Get.back(),
                    ),
                    GestureDetector(
                      child: Text(LocaleKeys.ok.ts, style: TextStyle(fontSize: 42.sp)),
                      onTap: () => Get.back(),
                    ),
                  ],
                ),
              )
            ],
          ),
        );
      },
    );
  }
}
